package cn.prophet.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import cn.prophet.utils.NumberPeriodsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import cn.prophet.bean.BjksProperties;
import cn.prophet.bean.BjksRecord;
import cn.prophet.mapper.BjksPropertiesMapper;
import cn.prophet.mapper.BjksRecordMapper;
import cn.prophet.service.BjKRecordService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

@Component
@Slf4j
public class LotteryTask {
    @Resource
    private BjksPropertiesMapper bjksPropertiesMapper;
    @Resource
    private BjKRecordService recordService;
    @Scheduled(cron="0 0/10 9-23 * * *")
    public void autoAddBjk3() {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        //时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //分
        int minute = calendar.get(Calendar.MINUTE);
        log.info("定时任务："+hour+"mm:"+minute);
        if(23==hour&&minute>=50){
            return;
        }
        byte recordType ;
        if(9==hour&&0==minute){
            recordType =1;
        }else if(23==hour&&40==minute){
            recordType = 2;
        }else{
            recordType =0;
        }
        //每天9.00点是第一次开始  当天开到第几次了
        int cc = ((hour-9)*60+minute)/10+1;
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String formatDate = format.format(date);
        String current = formatDate+ NumberPeriodsUtils.getNumber(cc,2);
        recordService.addRecord(current,date,recordType, (byte) 1);
    }
    @Scheduled(cron="0 0 8 * * *")
    public void autoAddBjk3Properties() {
        //每天8点触发
        BjksProperties pro = bjksPropertiesMapper.selectByPrimaryKey(1);
        int firstNum = pro.getFristnum();
        firstNum = firstNum+pro.getCount();
        BjksProperties currentPro = new BjksProperties();
        currentPro.setId(1);
        currentPro.setFristnum(firstNum);

        bjksPropertiesMapper.updateByPrimaryKeySelective(currentPro);
    }
    
    @Scheduled(cron="0/5 * 9-23 * * *")
    public void autoAddBjkList() {
        //每天9-24点之前触发  没间隔5秒钟

        recordService.getBjGovList();
    }

    /**
     * 江苏快三 8.30 - 22.00
     */
    @Scheduled(cron = "0 0/10 8-22 * * *")
    public void autoAddJsk3(){
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        //时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //分
        int minute = calendar.get(Calendar.MINUTE);

        if((hour==8&&minute<30)||(hour==22&&minute>0)){
            return;
        }

        byte recordType;
        if(8==hour&&30==minute){
            recordType =1;
        }else if(22==hour&&0==minute){
            recordType = 2;
        }else{
            recordType =0;
        }
        //每天9.00点是第一次开始  当天开到第几次了
        int cc = ((hour-8)*60+minute-30)/10+1;

        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String formatDate = format.format(date);
        String current = formatDate+ NumberPeriodsUtils.getNumber(cc,2);
        recordService.addRecord(current,date,recordType, (byte) 2);


    }

    /**
     * 宁夏快三 9.27 - 22.17
     */
    @Scheduled(cron = "0 0/10 9-21 * * *")
    public void autoAddNxk3(){
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        //时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        //分
        int minute = calendar.get(Calendar.MINUTE);

        byte recordType;
        if(9==hour&&0==minute){
            recordType =1;
        }else if(21==hour&&50==minute){
            recordType = 2;
        }else{
            recordType =0;
        }
        //每天9.00点是第一次开始  当天开到第几次了
        int cc = ((hour-9)*60+minute-0)/10+1;

        SimpleDateFormat format = new SimpleDateFormat("yyMMdd");
        String formatDate = format.format(date);
        String current = formatDate+ NumberPeriodsUtils.getNumber(cc,3);
        recordService.addRecord(current,date,recordType, (byte) 3);
    }


    @Scheduled(cron="0/5 * 8-22 * * *")
    public void autoAddNxkList() {
        //每天9-24点之前触发  没间隔5秒钟

        recordService.getNxGovList();
        recordService.getJsGovList();
    }

    
    
}
